{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Learning linear regression from an example on scikit-learn\n",
    "\n",
    "The example code is uploaded on http://scikit-learn.org/stable/auto_examples/linear_model/plot_ols.html\n",
    "At first, we should import necessary libraries - numpy, matplotlib, and scikit-learn.\n",
    "With these libraries, you do not need to implement linear regression and other analytic functions, such as computing r2 score, MSE errors, and drawing graphs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets, linear_model\n",
    "from sklearn.metrics import mean_squared_error, r2_score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Load the diabetes dataset, which is already introduced on a scikit-learn tutorial page."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'DESCR': 'Diabetes dataset\\n================\\n\\nNotes\\n-----\\n\\nTen baseline variables, age, sex, body mass index, average blood\\npressure, and six blood serum measurements were obtained for each of n =\\n442 diabetes patients, as well as the response of interest, a\\nquantitative measure of disease progression one year after baseline.\\n\\nData Set Characteristics:\\n\\n  :Number of Instances: 442\\n\\n  :Number of Attributes: First 10 columns are numeric predictive values\\n\\n  :Target: Column 11 is a quantitative measure of disease progression one year after baseline\\n\\n  :Attributes:\\n    :Age:\\n    :Sex:\\n    :Body mass index:\\n    :Average blood pressure:\\n    :S1:\\n    :S2:\\n    :S3:\\n    :S4:\\n    :S5:\\n    :S6:\\n\\nNote: Each of these 10 feature variables have been mean centered and scaled by the standard deviation times `n_samples` (i.e. the sum of squares of each column totals 1).\\n\\nSource URL:\\nhttp://www4.stat.ncsu.edu/~boos/var.select/diabetes.html\\n\\nFor more information see:\\nBradley Efron, Trevor Hastie, Iain Johnstone and Robert Tibshirani (2004) \"Least Angle Regression,\" Annals of Statistics (with discussion), 407-499.\\n(http://web.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf)\\n',\n",
       " 'data': array([[ 0.03807591,  0.05068012,  0.06169621, ..., -0.00259226,\n",
       "          0.01990842, -0.01764613],\n",
       "        [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n",
       "         -0.06832974, -0.09220405],\n",
       "        [ 0.08529891,  0.05068012,  0.04445121, ..., -0.00259226,\n",
       "          0.00286377, -0.02593034],\n",
       "        ..., \n",
       "        [ 0.04170844,  0.05068012, -0.01590626, ..., -0.01107952,\n",
       "         -0.04687948,  0.01549073],\n",
       "        [-0.04547248, -0.04464164,  0.03906215, ...,  0.02655962,\n",
       "          0.04452837, -0.02593034],\n",
       "        [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n",
       "         -0.00421986,  0.00306441]]),\n",
       " 'feature_names': ['age',\n",
       "  'sex',\n",
       "  'bmi',\n",
       "  'bp',\n",
       "  's1',\n",
       "  's2',\n",
       "  's3',\n",
       "  's4',\n",
       "  's5',\n",
       "  's6'],\n",
       " 'target': array([ 151.,   75.,  141.,  206.,  135.,   97.,  138.,   63.,  110.,\n",
       "         310.,  101.,   69.,  179.,  185.,  118.,  171.,  166.,  144.,\n",
       "          97.,  168.,   68.,   49.,   68.,  245.,  184.,  202.,  137.,\n",
       "          85.,  131.,  283.,  129.,   59.,  341.,   87.,   65.,  102.,\n",
       "         265.,  276.,  252.,   90.,  100.,   55.,   61.,   92.,  259.,\n",
       "          53.,  190.,  142.,   75.,  142.,  155.,  225.,   59.,  104.,\n",
       "         182.,  128.,   52.,   37.,  170.,  170.,   61.,  144.,   52.,\n",
       "         128.,   71.,  163.,  150.,   97.,  160.,  178.,   48.,  270.,\n",
       "         202.,  111.,   85.,   42.,  170.,  200.,  252.,  113.,  143.,\n",
       "          51.,   52.,  210.,   65.,  141.,   55.,  134.,   42.,  111.,\n",
       "          98.,  164.,   48.,   96.,   90.,  162.,  150.,  279.,   92.,\n",
       "          83.,  128.,  102.,  302.,  198.,   95.,   53.,  134.,  144.,\n",
       "         232.,   81.,  104.,   59.,  246.,  297.,  258.,  229.,  275.,\n",
       "         281.,  179.,  200.,  200.,  173.,  180.,   84.,  121.,  161.,\n",
       "          99.,  109.,  115.,  268.,  274.,  158.,  107.,   83.,  103.,\n",
       "         272.,   85.,  280.,  336.,  281.,  118.,  317.,  235.,   60.,\n",
       "         174.,  259.,  178.,  128.,   96.,  126.,  288.,   88.,  292.,\n",
       "          71.,  197.,  186.,   25.,   84.,   96.,  195.,   53.,  217.,\n",
       "         172.,  131.,  214.,   59.,   70.,  220.,  268.,  152.,   47.,\n",
       "          74.,  295.,  101.,  151.,  127.,  237.,  225.,   81.,  151.,\n",
       "         107.,   64.,  138.,  185.,  265.,  101.,  137.,  143.,  141.,\n",
       "          79.,  292.,  178.,   91.,  116.,   86.,  122.,   72.,  129.,\n",
       "         142.,   90.,  158.,   39.,  196.,  222.,  277.,   99.,  196.,\n",
       "         202.,  155.,   77.,  191.,   70.,   73.,   49.,   65.,  263.,\n",
       "         248.,  296.,  214.,  185.,   78.,   93.,  252.,  150.,   77.,\n",
       "         208.,   77.,  108.,  160.,   53.,  220.,  154.,  259.,   90.,\n",
       "         246.,  124.,   67.,   72.,  257.,  262.,  275.,  177.,   71.,\n",
       "          47.,  187.,  125.,   78.,   51.,  258.,  215.,  303.,  243.,\n",
       "          91.,  150.,  310.,  153.,  346.,   63.,   89.,   50.,   39.,\n",
       "         103.,  308.,  116.,  145.,   74.,   45.,  115.,  264.,   87.,\n",
       "         202.,  127.,  182.,  241.,   66.,   94.,  283.,   64.,  102.,\n",
       "         200.,  265.,   94.,  230.,  181.,  156.,  233.,   60.,  219.,\n",
       "          80.,   68.,  332.,  248.,   84.,  200.,   55.,   85.,   89.,\n",
       "          31.,  129.,   83.,  275.,   65.,  198.,  236.,  253.,  124.,\n",
       "          44.,  172.,  114.,  142.,  109.,  180.,  144.,  163.,  147.,\n",
       "          97.,  220.,  190.,  109.,  191.,  122.,  230.,  242.,  248.,\n",
       "         249.,  192.,  131.,  237.,   78.,  135.,  244.,  199.,  270.,\n",
       "         164.,   72.,   96.,  306.,   91.,  214.,   95.,  216.,  263.,\n",
       "         178.,  113.,  200.,  139.,  139.,   88.,  148.,   88.,  243.,\n",
       "          71.,   77.,  109.,  272.,   60.,   54.,  221.,   90.,  311.,\n",
       "         281.,  182.,  321.,   58.,  262.,  206.,  233.,  242.,  123.,\n",
       "         167.,   63.,  197.,   71.,  168.,  140.,  217.,  121.,  235.,\n",
       "         245.,   40.,   52.,  104.,  132.,   88.,   69.,  219.,   72.,\n",
       "         201.,  110.,   51.,  277.,   63.,  118.,   69.,  273.,  258.,\n",
       "          43.,  198.,  242.,  232.,  175.,   93.,  168.,  275.,  293.,\n",
       "         281.,   72.,  140.,  189.,  181.,  209.,  136.,  261.,  113.,\n",
       "         131.,  174.,  257.,   55.,   84.,   42.,  146.,  212.,  233.,\n",
       "          91.,  111.,  152.,  120.,   67.,  310.,   94.,  183.,   66.,\n",
       "         173.,   72.,   49.,   64.,   48.,  178.,  104.,  132.,  220.,   57.])}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diabetes = datasets.load_diabetes()\n",
    "diabetes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that this dataset is composed of features - age, sex, bmi, bp, s1~s6 and targets.\n",
    "\n",
    "Let's look the data structure."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(442, 10)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diabetes_X = diabetes.data\n",
    "diabetes_X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(442,)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diabetes_Y = diabetes.target\n",
    "diabetes_Y.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The target describe some 442 values related with occurence of diabetes. We will only use one feature - bmi, as did in the tutorial on the official page of scikit-learn. We want to find the relationship between the feature, in this case bmi, and the targets. The label of 'bmi' feature is 2 and we only need these data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(442, 1)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diabetes_bmi = diabetes_X[:,np.newaxis, 2]\n",
    "diabetes_bmi.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We finish preparing data to find a relationship between the bmi and target values.\n",
    "Before to find the relationship, we have to split the dataset - train set and test set. We will use the train set to find the relationship, in other words, for a regression task, and will use the test to validate the relationship. We will use 400 samples of total 442 for the train set, and the rest for the test set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bmi_train = diabetes_bmi[:400]\n",
    "target_train = diabetes_Y[:400]\n",
    "\n",
    "bmi_test = diabetes_bmi[400:]\n",
    "target_test = diabetes_Y[400:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Yes, we finish preparing the ingredients. Let's cook the data. At first, we should set a model what we want to do - linear regression task."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "regr = linear_model.LinearRegression()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, optimize the model by just typing simple keywords."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regr.fit(bmi_train, target_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can obatin the optimized coefficients of the task."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 955.70303385])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regr.coef_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We should check the performance of the task using the test set.\n",
    "The performance can be measured by various way, however, we check the mean-squared-error and r2-variance score in here. Learn further at this link - https://en.wikipedia.org/wiki/Coefficient_of_determination."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 196.51241167,  109.98667708,  121.31742804,  245.95568858,\n",
       "        204.75295782,  270.67732703,   75.99442421,  241.8354155 ,\n",
       "        104.83633574,  141.91879342,  126.46776938,  208.8732309 ,\n",
       "        234.62493762,  152.21947611,  159.42995399,  161.49009053,\n",
       "        229.47459628,  221.23405012,  129.55797419,  100.71606266,\n",
       "        118.22722323,  168.70056841,  227.41445974,  115.13701842,\n",
       "        163.55022706,  114.10695016,  120.28735977,  158.39988572,\n",
       "        237.71514243,  121.31742804,   98.65592612,  123.37756458,\n",
       "        205.78302609,   95.56572131,  154.27961264,  130.58804246,\n",
       "         82.17483382,  171.79077322,  137.79852034,  137.79852034,\n",
       "        190.33200206,   83.20490209])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_pred = regr.predict(bmi_test)\n",
    "y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3171.1118016053833"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_error = mean_squared_error(target_test, y_pred)\n",
    "mse_error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.42720426706720194"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r2 = r2_score(target_test, y_pred)\n",
    "r2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHhVJREFUeJzt3XuQnHWd7/H3d5JwGRQSIHBCwvQg\nICvIZSECWyKFF24RBeuwgo5sUKrGPSuuUqdc8bSWFnWypbCLyi4lDAeO4WQEETxyObBuQNSwdYST\nsFwCEZLoTBKSIgPhEplsCJnv+eN5JunM9OXp6e7n+nlVdXXP8/x65tfP9Hz6N7/f7/k95u6IiEh+\ndSVdARER6SwFvYhIzinoRURyTkEvIpJzCnoRkZxT0IuI5JyCXkQk5xT0IiI5p6AXEcm56UlXAODg\ngw/23t7epKshIpIpK1aseMXdZzcql4qg7+3tZfny5UlXQ0QkU8xsOEo5dd2IiOScgl5EJOcU9CIi\nOaegFxHJOQW9iEjOKehFJBUGBwfp7e2lq6uL3t5eBgcHk65SbqRieqWIFNvg4CD9/f2Mjo4CMDw8\nTH9/PwB9fX1JVi0X1KIXkcSVy+VdIT9udHSUcrmcUI3yRUEvIolbt25dU9ulOQp6EUlcT09PU9ul\nOQp6EUncokWL6O7u3mNbd3c3ixYtSqhG+aKgF5HE9fX1MTAwQKlUwswolUoMDAxoILZNzN3rFzDb\nB/gtsDfBLJ273f3b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N8Plw237ACuAZ4Dngh2R0xgmwAHiRYGZFOdx2DfDJ8PE+4e98TfgeeE/Fc8vh814A\nzk/6tSR9TID/HL4fngaeBD6R9GuJ6Xh8IMyLt4BXgecqnjvp76dIN50ZKyKSczozVkQk5xT0IiI5\np6AXEck5Bb2ISM4p6EVEck5BLyKScwp6EZGcU9CLiOTc/we+lFfe1iUUvwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x9a58780>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(bmi_test, target_test, color='black')\n",
    "plt.plot(bmi_test, y_pred, color='blue', linewidth=3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The blue line is the model obtained by using the train set, and black dots are actual values for each bmi sample.\n",
    "\n",
    "In this exercise, we do not implement a linear regression model, analytics, and plotting. But, we can easily do those things by import python libraries and using proper implemented functions.\n",
    "Capturing the things what we have to know and have to do is the first step to do data science. Before that, of critical, we should prepare dataset to construct our model at first. I hope that students do not be afraid to do data science and just enjoy with python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
